﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NiceManage.Common;
using NiceManage.Models;
using Newtonsoft.Json;

namespace NiceManage.Controllers
{
    public class UsersController : Controller
    {
        // GET: /<controller>/
        public IActionResult Index()
        {
            
            return View();
        }
        public JsonResult AddEntity(m_user m_User)
        {
            var result= new ResultEntity<m_user>();
            var _user = new Users();
            _user.Add_User(m_User);
            result.code = 0;
            result.msg = "添加成功！";
            return Json(result);
        }
        public JsonResult GetResult(int page=1,int limit=10)
        {
            try
            {
                var re = new ResultEntity<m_user>();
                var _user = new Users();
                var total = 0;
                var list = _user.GetListPage(page, limit, ref total);
                re.code = 0;
                re.count = total;
                re.msg = "OK";
                re.data = list;
                return Json(re);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public JsonResult UpdateEntity(m_user m_User)
        {
            var re = new ResultEntity<m_user>();
            var _user = new Users();
            var entity = _user.Update_User(m_User);
            re.code = 0;
            return Json(re);
        }

        public JsonResult DeleteEntityByID(int ID)
        {
            var re = new ResultEntity<m_user>();
            var _user = new Users();
            var entity = _user.Delete_User(ID);
            re.code = 0;
            return Json(re);
        }

    }
  
}
